import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-06-24
 * Time: 21:33
 */
public class test2 {
    public List<List<String>> groupAnagrams(String[] strs) {
        // key是字符串str  , value是与str相同的列表
        Map<String,List<String>> map = new HashMap<String,List<String>>();
        for(String str:strs){
            char[] ch = str.toCharArray();
            Arrays.sort(ch);
            String key = new String(ch);
            List<String> list = map.getOrDefault(key,new ArrayList<String>());
            list.add(str);
            map.put(key,list);
        }
        return new ArrayList<List<String>>(map.values());
    }
}
